package com.xjj.entity;

import cn.hutool.http.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author : 王泰元
 * @className: ResponseEntity
 * @description: TODO
 * @date : 2022/9/23 17:21
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseEntity<T> {

    private Integer code;
    private String message;
    private T data;


    public ResponseEntity(Integer code, String message) {
        this(code, message, null);
    }


    // 操作成功，200
    public static <T> ResponseEntity<T> SUCCESS(String message, T t) {
        return new ResponseEntity<>(HttpStatus.HTTP_OK, message, t);
    }


    // 未登录，401
    public static <T> ResponseEntity<T> UNAUTHORIZED(String message, T t) {
        return new ResponseEntity<>(HttpStatus.HTTP_UNAUTHORIZED, message, t);
    }


    // 无权限，403
    public static <T> ResponseEntity<T> NO_PERM(String message, T t) {
        return new ResponseEntity<>(HttpStatus.HTTP_FORBIDDEN, message, t);
    }


    // 系统错误（异常），500
    public static <T> ResponseEntity<T> FAIL(String message, T t) {
        return new ResponseEntity<>(HttpStatus.HTTP_INTERNAL_ERROR, message, t);
    }
}
